 include('shared.lua')
 language.Add("tardis","TARDIS");
 
function ENT:Draw()	self.Entity:DrawModel() end 

function ViewPoint( ply, origin, angles, fov )

	local tardis=LocalPlayer():GetNetworkedEntity("Tardis",LocalPlayer())
	local dist= -300
	
	if LocalPlayer():GetNWBool("isDriveTardis",false) and tardis~=LocalPlayer() and tardis:IsValid() then
		local view = {}
			view.origin = tardis:GetPos()+ply:GetAimVector():GetNormal()*dist
			view.angles = angles
		return view
	end
end
hook.Add("CalcView", "TardisView", ViewPoint)

function ENT:Think()

	local p = LocalPlayer()
	local shifting = self:GetNWBool("Shifting",false)
	
	if shifting then
		self:Lights()
	end
end

function ENT:Lights()

	local pos = self:GetPos() + self:GetUp() * 113
	local id = self:EntIndex();
	
	local dynlight = DynamicLight(id + 4096);
	dynlight.Pos = pos
	dynlight.Brightness = 2;
	dynlight.Size = 134;
	dynlight.Decay = 1024;
	dynlight.R = 255;
	dynlight.G = 255;
	dynlight.B = 255;
	dynlight.DieTime = CurTime()+1;
end

function HealthDisplay()

	local p = LocalPlayer()
	local tardis = p:GetNWEntity("Tardis",p)
	local health = tardis:GetNWInt("health",300)
	local drive = p:GetNWBool("isDriveTardis",false)
	
	if drive then
		draw.WordBox(9,ScrW()-240,ScrH()-115,"Health: "..health,"Default",Color(0,0,0,80),Color(255,220,0,220));
	end
end
hook.Add("HUDPaint","TardisHUD",HealthDisplay)